

import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
import { SDKLogicState, SDKState } from "../../SDKDefine";

/**
 * 积木广告
 */
@registerClass('QQBlockAd')
export default class QQBlockAd extends BaseAd {


    load(): void {

    }


    // preload(s: SDKState) {
    //     this.setLogicState(s)
    //     this.setState(SDKState.loading)
    //     this.destroy()
    //     this.create()
    // }



    // open() {
    //     console.log('QQBlockAd  open state ', this.state)
    //     if (this.state == SDKState.loadSucess) {
    //         this.show()
    //     } else {
    //         this.preload()

    //     }
    // }
    onResize(size: any) {

        let winSize = this.sdk.getSystemInfoSync();

        // console.log('QQBlockAd onResize  ', size, ' winSize ', winSize)
        console.log(size.width, size.height);
        if (size.width != 0 && size.height != 0) {
            this.updateSize()
        }
    }

    updateSize() {
        if (!this.ad) {
            return;
        }
        // let winSize = this.sdk.getSystemInfoSync();
        // console.log('QQBlockAd updateSize ', this.rx, this.ry)
        let left = this.style.left;
        let top = this.style.top;
        this.ad.style.left = left;
        this.ad.style.top = top// = this.getStyle()
    }

    // getStyle() {
    //     let winSize = this.sdk.getSystemInfoSync();
    //     let left = winSize.windowWidth * this.rx;
    //     let top = winSize.windowHeight * this.ry;

    //     return {
    //         left: left,
    //         top: top
    //     }
    // }




    create() {
        if (!this.ad) {
            this.ad = this.sdk.createBlockAd({
                adUnitId: this.adUnitID,
                style: this.getStyle(),
                size: this.param.count,
                orientation: this.param.orientation,
            })
            this.ad.onResize(this.getFunc(this.onResize))
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
        }
    }

    show() {

        if (this.ad) {
            this.ad.show()
        }


    }

    hide() {

        if (this.ad) {
            console.log(' blckad hide ')
            this.ad.hide()
        }
    }

    destroy() {
        if (this.ad) {
            this.ad.destroy()
            this.ad = null;
        }
    }
}